<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>${title }</title>
    <link rel="stylesheet" href="${basePath}/static/bootstrap/css/bootstrap.css"/>
    <link href="${basePath}/static/layer/skin/default/layer.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/basic.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/login.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css1/lyh.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/list.css" rel="stylesheet" type="text/css">
	<link rel="stylesheet" type="text/css" href="${basePath}/static/css1/index.css">
	<link rel="stylesheet" type="text/css"
	href="${basePath}/static/assert/jquery-ui/jquery-ui.css">
    <script type="text/javascript" src="${basePath}/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="${basePath}/static/assert/jquery-ui/jquery-ui.js"></script>
	<script type="text/javascript" src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${basePath}/static/page/jqPaginator/jqPaginator.js"></script>
    <script type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
    <link href="${basePath}/static/layer/layer_defined.css" rel="stylesheet" type="text/css">
    <style type="text/css">
    	.btn{
    		padding: 6px;
    	}
    	select {
		    width: 160px;
		    height: 28px;
		    text-align: left;
		    text-indent: 5px;
		    line-height: 28px;
		    border: #e3e5e4 solid 1px;
		}
		.input_box{
		    height: 30px;
		    border: none;
		    border-bottom: 1px solid #FFC99D;
		    text-indent: 5px;
		}
    </style>
</head>
<body class="bj">
<!--头部-->
	<%@include file="/WEB-INF/templates/common/header.jsp"%>
	<!------导航条-->
	<%@include file="/WEB-INF/templates/common/navigation.jsp"%>

<!--内容部分-->
<div class="list_main lay_out" class="clearfix">
    <div class="list_DH">
        <%@include file="/WEB-INF/templates/common/queryNav.jsp"%>
    </div>
    <div class="list_NR">
  		<div class="loc">
  			 <h3>全文检索</h3>
  		</div>
	<div id="fullSearch">
	    <table width="99%" style="margin:0 auto;" cellspacing="0" border="0" cellpadding="0">
	        <input type="hidden"  id="sex_name_num" value="0">
	        <input type="hidden"  id="medical_pay_type_name_num" value="0">
	        <input type="hidden"  id="in_hospital_state_name_num" value="0">
	        <input type="hidden"  id="out_dept_name_num" value="0">
	           
	        <input type="hidden"  id="main_disease_name_num" value="0">
	        <input type="hidden"  id="second_disease_name_num" value="0">
	        <input type="hidden"  id="patient_name_num" value="0">
	        <input type="hidden"  id="id_number_num" value="0">
	        <input type="hidden"  id="mr_id_num" value="0">
	        <input type="hidden"  id="visit_number_num" value="0">
	        <input type="hidden"  id="out_hospital_date_time_num" value="0">
	                   
	         <thead>
	            <tr>
                   <td class="tdLabel_4" width="30%">检索内容</td>
                   <td class="tdLabel_4" width="20%">操作符</td>
                   <td class="tdLabel_4" width="30%">检索条件</td>
                   <td class="tdLabel_4" width="20%">操作</td>
                </tr>             
	         </thead>
             <tbody id="SearchTable">
                <tr class="searchList">
                     <td class="tdLabel_5">
                      <select name="search_Text" onchange="changeSelect(this)">
                                        <option typeName="1" value="">-请选择-</option>
                                        <option typeName="1" value ="patient_name">姓名</option>
										<option typeName="1" value ="id_number">身份证号</option>
										<option typeName="1" value ="mr_id">识别码(ID)</option>
										<!-- <option typeName="1" value ="visit_number">住院次数</option> -->
										<option typeName="2"  value ="sex_name">性别</option>
										<option typeName="2" value="medical_pay_type_name">付费方式</option>
										<!-- <option typeName="1" value="visit_number">住院次数</option> -->
										<option typeName="2" value="in_hospital_state_name">入院状态</option>
										<option typeName="2" value="out_dept_name">出院科室</option>
										<option typeName="1" value="out_hospital_date_time">出院时间</option>
										<option typeName="2" value="out_hospital_type">离院方式</option>
                                    	<option typeName="2" value="main_disease_name">主要诊断</option>
                                    	<option typeName="2" value="second_disease_name">次要诊断</option>
                                    </select>
                   
                                </td>
                                <td class="tdLabel_5">
                                    <select name="search_Operators">
                                        <option value="">-请选择-</option>
                                        <option value="1">-等于-</option>
                                        <option value="2">-小于-</option>
                                        <option value="3">-大于-</option>
                                        <option value="4">-小于等于-</option>
                                        <option value="5">-大于等于-</option>
                                      <!--   <option value="6">-模糊匹配-</option> -->
                                    </select>
                                </td>
                                
                                <td class="tdLabel_5">
                                   <input   name="search_Term" id="content" style="width:200px" class="input_box">
                                </td>
                                
                                <td align="center" class="tdLabel_5 index_search_delete">
	                                  
	                                 	 <a href="javascript:void(0);" onclick="add(this)"  class="int">新增检索条件</a> 
	                                 
                                </td>
                            </tr>
                          </tbody>
           </table>
	 </div>
    <div style="float:right;margin-right:5px;margin-top:5px;">
         <input type="submit" value="检索" onclick="fullTextSearch()" class="btn_qx">
             <!-- <input type="button" value="新增" onclick="add()"class="btn_qx"> -->
    </div>
                                    
                             
	<div style="margin-top: 50px;">
	     <table class="Search_tableList" cellpadding="0" cellspacing="0">
	              <thead>
	                 <tr>
	                 	<td class="tdLabel_4">序号</td>
	                    <td class="tdLabel_4">姓名</td>
	                    <td class="tdLabel_4">身份证号</td>
	                    <td class="tdLabel_4">ID号</td>
	                    <td class="tdLabel_4">出院科室</td>
	                    <td class="tdLabel_4">出院日期</td>
	                    <td class="tdLabel_4">操作</td>
	                </tr>
	               
	               </thead>
                <tbody id="tbody">
	                 
				</tbody>
			</table>
    </div>

</div>
</div>

<!------页脚部分--------->
<%@include file="/WEB-INF/templates/common/footer.jsp"%>

 <!--JS部分-->
<script type="text/javascript">

function fullTextSearch(){
		//console.log(' and '.length)
		var searchStr="",search_Text,search_Operators,search_Term;
		//获取检索tr的个数
	    var searchTr_length=$(".searchList").length;
		var select = 0;
		var arr=new Array();
		$.each($(".searchList"),function(i,item){
    		search_Text=$(item).find("select[name='search_Text']").val();
        	search_Operators=$(item).find("select[name='search_Operators']").val();
        	search_Term=$(item).find("input[name='search_Term']").val();


        	if(!search_Text||!search_Operators||!search_Term){
        		layer.alert('检索内容、操作符、检索条件三者缺一不可!',{icon:5});
        		select = 1 ;
        		return false;
        	}
        	arr.push({"patameterName":search_Text,"operationalName":search_Operators,"parameterValue":search_Term});
        });
		
		if(!arr){
			layer.alert('查询参数不能为空!',{icon:5});
			return;
		}
		
		$.ajax({  
		    type: "POST",  
		    url: "${pageContext.request.contextPath}/fullText/fulltextSearchJson",  
		    data: JSON.stringify(arr),//将对象序列化成JSON字符串  
		    dataType:"json",  
		    contentType : 'application/json;charset=utf-8', //设置请求头信息  
		    success: function(data){ 
		    	if(data.length==0){
		    		layer.alert('数据为空!',{icon:5});
		    		$("#tbody").html("");
		    	}else{
		    		//console.log(data);
		    		var html=""
		    		$.each(data,function(index,value){
		    			   html+=" <tr>"+
		    			       "<td class='tdLabel_5'>"+(index+1)+"</td>"+
                 			   "<td class='tdLabel_5'>"+value.patientName+"</td>"+
			                   " <td class='tdLabel_5'>"+value.idNumber+"</td>"+
			                   " <td class='tdLabel_5'>"+value.mrId+"</td>"+
			                   " <td class='tdLabel_5'>"+value.outDeptName+"</td>"+
			                   " <td class='tdLabel_5'>"+value.outHospitalDateTime+"</td>"+
                  			   " <td class='tdLabel_5'><a target='_blank' href='${corePath}/medical_record/print?visitGuid="+value.visitGuid+"' class='int'>查看病案</a></td>"+
	              			   "</tr>";
		    		});
		    		
		    		$("#tbody").html(html);
		    	}
		    },  
		    error: function(res){  
		    }  
		}); 
		
		
	
		
	
}

/* 新增检索条件事件  */
function add(ev){
	var trList=$(ev).closest('tr');
	var search_Text=trList.find("select[name='search_Text']").val();
	var search_Operators=trList.find("select[name='search_Operators']").val();
	var search_Term=trList.find("input[name='search_Term']").val();
	
	if(!search_Text||!search_Operators||!search_Term){
		layer.alert('检索内容、操作符、检索条件三者缺一不可!',{icon:5});
	}
	
     var htmlTr=$(trList).clone(true);
     $(htmlTr).find("input[name='search_Term']").attr("readOnly","true");
     $(htmlTr).find(".index_search_delete:last").html("").html("<a href='javascript:void(0);' onclick='delet(this)' class='int'>删除</a>");
     $(htmlTr).find("select[name='search_Text'] option[value='"+search_Text+"']").attr("selected",true);
     $(htmlTr).find("select[name='search_Operators'] option[value='"+search_Operators+"']").attr("selected",true);
     
     $("#SearchTable tr").last().before(htmlTr);
     trList.find("select[name='search_Text']").val("");
 	 trList.find("select[name='search_Operators']").val("");
 	 trList.find("input[name='search_Term']").val("");
     
}




function changeSelect(obj){
	var contentType=$(obj).val();
	var contentElement= $(obj).parents("tr").find("input[name='search_Term']");
	$(obj).parents("tr").siblings().each(function(){
		$(this).find("input[name='search_Term']").attr("class","input_box");
	});
	
	var num = $("#"+contentType+"_num").val();
	//var contentId=(num==0?contentType:contentType+num);
	
	uISearch(contentType,contentElement);
	
}

/* function  changeInput(obj){
	var $this=$(obj);
	var contentType = $(obj).parents("tr").find("select[name='search_Text']").val();
	$(obj).parents("tr").siblings().each(function(){
		$(this).find("input[name='search_Term']").attr("class","input_box");
	});
	if(!contentType){
		return;
	}
	uISearch(contentType,contentType,$this);
}  */




function uISearch(contentType,obj){
	var num = $("#"+contentType+"_num").val();
	var contentId=(num==0?contentType:contentType+num);
	obj.attr("id",contentId);
	//出院时间为日期
	if(contentType=="out_hospital_date_time"){
		$("#"+contentId).attr("title","时间格式为:yyyy-MM-dd");
		//$("#"+contentId).attr("onfocus","WdatePicker({dateFmt:'yyyy-MM-dd'})");
		initUI(contentId,null);
	}
	//主要诊断和次要诊断
	if(contentType=="main_disease_name" || contentType=="second_disease_name"){
		var url = "${basePath}/basicInfo/ajaxDiagDieaseJson";
		initUI(contentId,url);
	}
	//性别
	if(contentType=="sex_name"){
		var url = "${basePath}/basicInfo/ajaxSexNameJson";
		initUI(contentId,url);
	}
	
	//姓名
	if(contentType=="patient_name"){	
		initUI(contentId,null);
	}
	
	//识别码(ID)
	if(contentType=="mr_id"){	
		initUI(contentId,null);
	}
	
/* 	//住院次数
	if(contentType=="visit_number"){	
		initUI(contentId,null);
	} */
	
	                                                                                 
	
	
	
	//身份证号
	if(contentType=="id_number"){	
		initUI(contentId,null);
	}
	
	//身份证号
	if(contentType=="id_number"){	
		initUI(contentId,null);
	}
	
	//入院状态
	if(contentType=="in_hospital_state_name"){
		var url = "${basePath}/basicInfo/ajaxInHospitalStateJson";
		initUI(contentId,url);
	}
	
	//出院科室
	if(contentType=="out_dept_name"){
		var url = "${basePath}/basicInfo/ajaxDeptNameJson";
		initUI(contentId,url);
	}
	
	
	//出院类型
	if(contentType=="out_hospital_type"){
		var url = "${basePath}/basicInfo/ajaxOutHospitalTypeJson";
		initUI(contentId,url);
	}
	
	//medical_pay_type_name
	if(contentType=="medical_pay_type_name"){
		var url = "${basePath}/basicInfo/ajaxPaymentTypeJson";
		initUI(contentId,url);
	}
	
	
	
	
	num++;
	$("#"+contentType+"_num").val(num);
}


/* 删除检索条件 */
function delet(ev){
	 var that=$(ev);
	 $(that).closest("tr").remove(); 
}


/* $(function(){
	//初始化xinxi
	init();
});
 */
/* function init(){
	var type;
	 $("#searchText option").each(function () {
	     console.log($(this));
	       var val = $(this).val(); //获取单个value
	       type=$(this).attr("typeName");
	    	 alert(type);
	     	if(type==2){
	     		 initUI(val);
	     	}
	    	
	 });
	 
	 for(var i=1;i<5;i++){
		 $("#searchText option").each(function () {
		      
		       var val = $(this).val(); //获取单个value
		       var type=$(this).attr("typeName");
		    	   
		    	   initUI(val+i);
		      
		 });
	 }
	 
} */


function initUI(id,url){
	 $( "#"+id ).autocomplete({
	      minLength: 0,
	      source: function( request, response ) {
	   
	    	 var queryName = request.term;
	    	 $( "#"+id ).val(queryName);
	    	 if(queryName!=null && queryName!=''){
	    		 $.ajax({
			    		type:"post",
			    		url: url,
			    		dataType: "json",
			    		data:{
							queryName: request.term
						},
						success: function( data ) {
							response( $.map( data, function( item ) {
								return {
									name:item.name,
									code:item.code
								}
							}));
						}
			    	 }); 
	    	 }
	    	
	    	 
	    	
	      },
	      /* focus: function( event, ui ) {
	        $( "#diag_disease_name" ).val( ui.item.name );
	        return false;
	      }, */
	      select: function( event, ui ) {
	        $(  "#"+id  ).val( ui.item.name );
	      
	 
	        return false;
	      }
	    })
	    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
	      return $( "<li>" )
	        .append( "<a>" + item.name+"-"+item.code +"</a>" )
	        .appendTo( ul );
	    };
}

</script>



</body>
</html>